using System;
using System.Data;

using SqlHelperForCry.Common;

namespace Torch.WL.Entity
{
    [Table("Tb_Sys_Users", "UserID", "Torch.WL.ConnectionString")]
	public class Tb_Sys_Users : Info
	{
		#region SQL column name consts 
		public const string SQLCOL_USERID = "UserID";
		public const string SQLCOL_USERNAME = "UserName";
		public const string SQLCOL_DOMAINNAME = "DomainName";
		public const string SQLCOL_SHOWNAME = "ShowName";
		public const string SQLCOL_PASSWORD = "Password";
		public const string SQLCOL_EMAIL = "Email";
		public const string SQLCOL_QUESTION = "Question";
		public const string SQLCOL_ANSWER = "Answer";
		public const string SQLCOL_ROLEID = "RoleID";
		public const string SQLCOL_USERGROUP = "UserGroup";
		public const string SQLCOL_CREATETIME = "CreateTime";
		public const string SQLCOL_LASTLOGINTIME = "LastLoginTime";
		public const string SQLCOL_STATUS = "Status";
		public const string SQLCOL_ISONLINE = "IsOnline";
		public const string SQLCOL_ISLIMIT = "IsLimit";
		#endregion


		#region Contructors
		/// <summary>
		/// Construct empty entity
		/// </summary>
		public Tb_Sys_Users () {}

		/// <summary>
		/// Construct entity by primary key, other fields will be assigned by 
		/// "Load" method.
		/// </summary>
		public Tb_Sys_Users (string UserName)
		{
			this.UserName = UserName;
		}
		#endregion

		public override void Init (DataRow row)
		{
			UserID = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_USERID]);
			UserName = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_USERNAME]);
			DomainName = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_DOMAINNAME]);
			ShowName = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_SHOWNAME]);
			Password = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_PASSWORD]);
			Email = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_EMAIL]);
			Question = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_QUESTION]);
			Answer = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_ANSWER]);
			RoleID = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_ROLEID]);
			UserGroup = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_USERGROUP]);
			CreateTime = (DateTime)ObjectType.DateTimeTypeHelper.Read(row[SQLCOL_CREATETIME]);
			LastLoginTime = (DateTime)ObjectType.DateTimeTypeHelper.Read(row[SQLCOL_LASTLOGINTIME]);
			Status = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_STATUS]);
			IsOnline = (bool)ObjectType.BooleanTypeHelper.Read(row[SQLCOL_ISONLINE]);
			IsLimit = (bool)ObjectType.BooleanTypeHelper.Read(row[SQLCOL_ISLIMIT]);
		}

		#region Properties 
		#region Property <int> UserID
		[Property("UserID", 4, SqlDbType.Int, true, false)]
		public int UserID 
		{
			get { return _UserID; }
			set { _UserID = value; }
		}
		private int _UserID = int.MinValue;
		#endregion

		#region Property <string> UserName
		[Property("UserName", 256, SqlDbType.NVarChar, false, true)]
		public string UserName 
		{
			get { return _UserName; }
			set { _UserName = value; }
		}
		private string _UserName = null;
		#endregion

		#region Property <string> DomainName
		[Property("DomainName", 100, SqlDbType.VarChar, false, false)]
		public string DomainName 
		{
			get { return _DomainName; }
			set { _DomainName = value; }
		}
		private string _DomainName = null;
		#endregion

		#region Property <string> ShowName
		[Property("ShowName", 100, SqlDbType.VarChar, false, false)]
		public string ShowName 
		{
			get { return _ShowName; }
			set { _ShowName = value; }
		}
		private string _ShowName = null;
		#endregion

		#region Property <string> Password
		[Property("Password", 256, SqlDbType.NVarChar, false, false)]
		public string Password 
		{
			get { return _Password; }
			set { _Password = value; }
		}
		private string _Password = null;
		#endregion

		#region Property <string> Email
		[Property("Email", 200, SqlDbType.NVarChar, false, false)]
		public string Email 
		{
			get { return _Email; }
			set { _Email = value; }
		}
		private string _Email = null;
		#endregion

		#region Property <string> Question
		[Property("Question", 200, SqlDbType.NVarChar, false, false)]
		public string Question 
		{
			get { return _Question; }
			set { _Question = value; }
		}
		private string _Question = null;
		#endregion

		#region Property <string> Answer
		[Property("Answer", 200, SqlDbType.NVarChar, false, false)]
		public string Answer 
		{
			get { return _Answer; }
			set { _Answer = value; }
		}
		private string _Answer = null;
		#endregion

		#region Property <int> RoleID
		[Property("RoleID", 4, SqlDbType.Int, false, false)]
		public int RoleID 
		{
			get { return _RoleID; }
			set { _RoleID = value; }
		}
		private int _RoleID = int.MinValue;
		#endregion

		#region Property <int> UserGroup
		[Property("UserGroup", 4, SqlDbType.Int, false, false)]
		public int UserGroup 
		{
			get { return _UserGroup; }
			set { _UserGroup = value; }
		}
		private int _UserGroup = int.MinValue;
		#endregion

		#region Property <DateTime> CreateTime
		[Property("CreateTime", 16, SqlDbType.DateTime, false, false)]
		public DateTime CreateTime 
		{
			get { return _CreateTime; }
			set { _CreateTime = value; }
		}
		private DateTime _CreateTime = DateTime.MinValue;
		#endregion

		#region Property <DateTime> LastLoginTime
		[Property("LastLoginTime", 16, SqlDbType.DateTime, false, false)]
		public DateTime LastLoginTime 
		{
			get { return _LastLoginTime; }
			set { _LastLoginTime = value; }
		}
		private DateTime _LastLoginTime = DateTime.MinValue;
		#endregion

		#region Property <int> Status
		[Property("Status", 4, SqlDbType.Int, false, false)]
		public int Status 
		{
			get { return _Status; }
			set { _Status = value; }
		}
		private int _Status = int.MinValue;
		#endregion

		#region Property <bool> IsOnline
		[Property("IsOnline", 1, SqlDbType.Bit, false, false)]
		public bool IsOnline 
		{
			get { return _IsOnline; }
			set { _IsOnline = value; }
		}
		private bool _IsOnline = false;
		#endregion

		#region Property <bool> IsLimit
		[Property("IsLimit", 1, SqlDbType.Bit, false, false)]
		public bool IsLimit 
		{
			get { return _IsLimit; }
			set { _IsLimit = value; }
		}
		private bool _IsLimit = false;
		#endregion
		#endregion


		public bool LoadByIdentity(int UserID)
		{
			return DataAccess.SelectByIdentity(this, Convert.ToInt64(UserID));
		}


		public bool DeleteByIdentity()
		{
			return DataAccess.DeleteByIdentity(this);
		}
	}
}
